<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new date</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.mongodate.html">« MongoDate</a></li>
      <li style="float: right;"><a href="mongodate.todatetime.html">MongoDate::toDateTime »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodate.html">MongoDate</a></li>
    <li>Creates a new date</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodate.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDate::__construct</h1>
  <p class="verinfo">(PECL mongo &gt;= 0.8.1)</p><p class="refpurpose"><span class="refname">MongoDate::__construct</span> &mdash; <span class="dc-title">Creates a new date</span></p>

 </div>

 <div id="mongodate.construct-soft-deprecation-notice" class="soft-deprecation-notice">
  <blockquote class="sidebar">
   <p class="para">This extension that defines this method
is deprecated. Instead, the <a href="" class="link">MongoDB</a> extension should be used.
Alternatives to this method include:</p>
   <ul class="simplelist">
    <li class="member"><span class="methodname"><strong>MongoDB\BSON\UTCDateTime::__construct()</strong></span></li>
   </ul>
  </blockquote>
 </div>

 <div class="refsect1 description" id="refsect1-mongodate.construct-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>MongoDate::__construct</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$sec</code><span class="initializer"> = time()</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$usec</code><span class="initializer"> = 0</span></span>)</div>

  <p class="para rdfs-comment">
   Creates a new date.  If no parameters are given, the current time is used.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodate.construct-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>

      <code class="parameter">sec</code>
     </dt>

     <dd>

      <p class="para">
       Number of seconds since the epoch (i.e. 1 Jan 1970 00:00:00.000 UTC).
      </p>
     </dd>

         
    
     <dt>

      <code class="parameter">usec</code>
     </dt>

     <dd>

      <p class="para">
       Microseconds. Please be aware though that MongoDB&#039;s resolution is
       <em class="emphasis">milliseconds</em> and not microseconds, which means this
       value will be truncated to millisecond resolution.
      </p>
     </dd>

         
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodate.construct-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    Returns this new date.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodate.construct-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-173">
   <p><strong>Example #1 <span class="function"><strong>MongoDate::__construct()</strong></span> example</strong></p>
   <div class="example-contents"><p>This example demonstrates creating a new date with the current time and a new date with a given time.</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$d&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">();<br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$d</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$d&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567890</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$d</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$d&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">(</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2009-05-01&nbsp;00:00:01"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$d</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
0.23660600 1235685067
0.00000000 1234567890
0.00000000 1241150401
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongodate.construct-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="mongodate.tostring.html" class="methodname" rel="rdfs-seeAlso">MongoDate::__toString()</a> - Returns a string representation of this date</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>